package com.jdk.mode.struct;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jukg
 * @date 2023/08/25 16:34
 * @description 组合模式，通过同一个基类，组建成一个树形结构
 */
public class Composite {
}

abstract class Corp{

    private String name;
    private long salary;

    public Corp(String name, long salary) {
        this.name = name;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public long getSalary() {
        return salary;
    }

    abstract void display();
}

class Manager extends Corp{

    private List<Corp> list = new ArrayList<>();

    public Manager(String name, long salary) {
        super(name, salary);
    }

    @Override
    void display() {
        System.out.println(super.getName());
        System.out.println(super.getSalary());
        for(Corp corp: list){
            corp.display();
        }
    }
}

class Leaf extends Corp{

    public Leaf(String name, long salary) {
        super(name, salary);
    }

    @Override
    void display() {
        System.out.println(super.getName());
        System.out.println(super.getSalary());
    }
}
